#coding=utf-8
import sdsource.web.sina as sina
import stockdb.misc as misc
'''
cs = misc.get_stcodes()
for c in cs:
    data = sina.get_ts(c)
    for ts in data.tss:
        misc.get_or_create_ts(c, ts[0], int(ts[1]))
'''
tss = misc.sess.query(misc.TradableShare).\
                filter_by(created_on='2008-04-14').all()

for ts in tss:
    s = ts.stock  
    print s  
    date = ts.date.isoformat()
    
    tds = s.tds_since(date)
    
    for td in tds:
        p =  td.price
        p.trade_rate = p.volume * 100.0 /(s.get_ts(date))
        
        misc.sess.commit()              
    
